﻿using Synthesize.BaseSet.ServiceInterface.Query.Authority;
using Microsoft.AspNetCore.Mvc;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Library.Common.Model;
using Synthesize.BaseSet.ServiceInterface.Dtos.Authority.Login;
using SMS.WebApi.App_Start.Attributes;

namespace SMS.WebApi.Areas.BaseSet.Controllers
{

    /// <summary>
    /// 用户信息操作接口
    /// </summary>
    public class LoginController : BaseSetBaseController
    {

        private readonly IUserQueryService _userQueryService;

        public LoginController(IUserQueryService userQueryService)
        {
            _userQueryService = userQueryService;
        }


        /// <summary>
        /// 获取验证码
        /// </summary>
        /// <param name="uniqueIdentifier">
        /// 客户端请求物理机唯一标识符【WEB/CS桌面获取物理机MAC地址；中转服务，获取请求客户端的唯一信息】
        /// </param>
        /// <remarks>
        /// 客户端请求物理机唯一标识符：可以在客户端生成一个可以保存5分钟或永久保存的GUID
        /// 验证码有效期：5分钟
        /// </remarks>
        /// <returns></returns>
        [HttpGet]
        [ApiHidden]
        [AllowAnonymous]
        public async Task<BaseApiResult<ValidateCodeOutput>> LoadValidateCode(string uniqueIdentifier)
        {
            return  await _userQueryService.LoadValidateCode(uniqueIdentifier);
        }

        /// <summary>
        /// 用户登录
        /// </summary>
        /// <param name="input"></param>
        /// <remarks>
        /// 客户端请求物理机唯一标识符：LoadValidateCode传递的uniqueIdentifier
        /// </remarks>
        /// <returns> 
        /// </returns>
        [HttpPost]
        [AllowAnonymous]
        public async Task<BaseApiResult<UserLoginInfoOutput>> UserLogin(UserInfoLoginInput input)
        {
            return await _userQueryService.UserLogin(input);
        }

        /// <summary>
        /// 刷新Token
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<BaseApiResult<UserLoginInfoOutput>> RefreshToken(RefreshTokenInput input)
        {
            return await _userQueryService.RefreshToken(input); ;
        }
    }
}
